
#ifndef GPSTK_LEOAttitude_HPP
#define GPSTK_LEOAttitude_HPP

////////////// //////////////
// author: kemin zhu
//
//
// 2019.5.13 Correct some errors, add a firstSec variable into the class.
//////////////// //////////////

#include <iostream>
#include <cmath>
#include <vector>

#include "MiscMath.hpp"
#include "CommonTime.hpp"
#include "YDSTime.hpp"
#include "Triple.hpp"
#include "Matrix.hpp"
#include "Vector.hpp"
#include "ReferenceSystem.hpp"
#include "MJD.hpp"

namespace gpstk
{

   class LEOAttitude
   {
   public:
      
      LEOAttitude()
         throw()
           : maxInterval(60), pRefSystem(NULL)
      {}
      
      virtual ~LEOAttitude()
      {}

         // load a LEO attitude file.
      virtual void loadFile(std::string filename);

         // getOffset
      virtual Triple OffsetInSRF2TRF(CommonTime& epoch, 
                                     Triple& offsetInSRF);

         // get offset from TRF to SRF
      virtual Triple OffsetInTRF2SRF(CommonTime& epoch, 
                                     Triple& offsetInTRF);


      virtual Matrix<double> S2TMatrix(CommonTime& epoch);
      virtual Matrix<double> T2SMatrix(CommonTime& epoch);

      virtual LEOAttitude& setRefSystem( ReferenceSystem& rs)
      {
         pRefSystem = &rs;
         return (*this);
      }
      

   private:

         // SRF to TRF Matrix
      virtual Matrix<double> SRF2TRF( CommonTime epoch, 
                                      double q0, double q1,
                                      double q2, double q3 );

         // TRF to SRF Matrix
      virtual Matrix<double> TRF2SRF( CommonTime epoch,
                                      double q0, double q1,
                                      double q2, double q3 );

         // SRF to CRF Matrix
      virtual Matrix<double> SRF2CRF( double q0, double q1,
                                      double q2, double q3 );

         // CRF to SRF Matrix
      virtual Matrix<double> CRF2SRF( double q0, double q1,
                                      double q2, double q3 );


      double maxInterval;

      std::map< CommonTime, std::vector<double> > QuaterMap;
      
      ReferenceSystem* pRefSystem;
      

   }; // END of "class LEOAttitude"



} // END of "namespace gpstk"

#endif
